//
//  YGForgetPwdViewController.m
//  yuanshangyiliao
//
//  Created by icholab on 2021/3/18.
//

#import "YGForgetPwdViewController.h"
#import "JGCountDownButton.h"
#import "YGResetPwdViewController.h"

@interface YGForgetPwdViewController ()<UITextViewDelegate>

@property(nonatomic, strong)UILabel *phoneLable;   //手机号
@property (nonatomic, strong)UILabel *codeLable;   //验证码
@property(nonatomic,strong)UIView *underLine;     //下划线
@property(nonatomic,strong)UIView *underLine2;
@property (nonatomic, strong)UITextField *phoneTextField;   //手机输入框
@property (nonatomic, strong) UITextField *codeTextField;       //验证码输入框
@property (nonatomic, strong) JGCountDownButton *countdownBtn;  //获取验证码
@property (nonatomic, strong) UIButton *nextBtn;


@end

@implementation YGForgetPwdViewController

#pragma mark - lift cycle

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"忘记密码";
    [self initView];
    [self initContraints];
    
    // Do any additional setup after loading the view.
}

#pragma mark - private
- (void)initView{
    [self.view addSubview:self.phoneLable];
    [self.view addSubview:self.codeLable];
    [self.view addSubview:self.phoneTextfield];
    [self.view addSubview:self.codeTextField];
    [self.view addSubview:self.countdownBtn];
    [self.view addSubview:self.nextBtn];
    [self.view addSubview:self.underLine];
    [self.view addSubview:self.underLine2];
}

-(void)initContraints{
    [self.phoneLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).offset(10);
        make.top.mas_equalTo(self.view.mas_top).offset(100);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(30);
    }];
    
    [self.codeLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).offset(10);
        make.top.mas_equalTo(self.phoneLable.mas_bottom).offset(10);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(30);
    }];
    
    [self.phoneTextfield mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.phoneLable.mas_right).offset(10);
        make.top.mas_equalTo(self.phoneLable.mas_top);
        make.width.mas_offset(150);
        make.height.mas_equalTo(30);
    }];
    
    [self.codeTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.codeLable.mas_right).offset(10);
        make.top.mas_equalTo(self.codeLable.mas_top);
        make.width.mas_offset(150);
        make.height.mas_equalTo(30);
    }];
    
    [self.underLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0.5);
        make.top.mas_equalTo(self.phoneLable.mas_bottom).offset(4);
        make.right.mas_equalTo(self.view.mas_right).offset(-1);
        make.height.mas_equalTo(1);
    }];
    
    [self.underLine2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0.5);
        make.top.mas_equalTo(self.codeLable.mas_bottom).offset(4);
        make.right.mas_equalTo(self.view.mas_right).offset(-1);
        make.height.mas_equalTo(1);
    }];
    
    [self.countdownBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.phoneLable.mas_top);
        make.height.mas_equalTo(self.phoneLable.mas_height);
        make.left.mas_equalTo(self.phoneTextfield.mas_right).offset(20);
        make.width.mas_equalTo(108);
    }];
    
    [self.nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.underLine2.mas_bottom).offset(40);
        make.left.mas_equalTo(self.view.mas_left).offset(10);
        make.right.mas_equalTo(self.view.mas_right).offset(-10);
        make.height.mas_equalTo(50);
            
    }];
    
}
-(void)clickNextAction{
    //进入修改密码页面
    YGResetPwdViewController *vc=[[YGResetPwdViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)clickAuthBtnAction:(UIButton *)sender{
    if (self.phoneTextField.text.length != 11) {
        //非11位
//        [self showTip:@"请输入正确的手机号"];
        return ;
    }
    [self requestImageVcode];
}

- (void)requestImageVcode {
    
    //请求验证码网络，
}
#pragma setter

- (UILabel *)phoneLable{
    if (!_phoneLable) {
        _phoneLable = [[UILabel alloc] init];
        _phoneLable.text=@"手机号：";
        _phoneLable.font=[UIFont systemFontOfSize:14];
        _phoneLable.textColor=UIColorFromRGB(0x888888);
        
        
    }
    return _phoneLable;
}

- (UITextField *)phoneTextfield{
    if (!_phoneTextField) {
        _phoneTextField= [[UITextField alloc] init];
        _phoneTextField.font= [UIFont systemFontOfSize:14];
        _phoneTextField.placeholder=@"请输入手机号码";
        _phoneTextField.layer.borderWidth=0;
        _phoneTextField.textAlignment=NSTextAlignmentLeft;
        _phoneTextField.delegate=self;
//        [_phoneTextfield addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
        
    }
    return _phoneTextField;
}

- (UILabel *)codeLable{
    if (!_codeLable) {
        _codeLable= [[UILabel alloc] init];
        _codeLable.text=@"验证码：";
        _codeLable.font= [UIFont systemFontOfSize:14];
        _codeLable.textColor=UIColorFromRGB(0x888888);
        
    }
    return _codeLable;
}

- (UITextField *)codeTextField{
    if (!_codeTextField) {
        _codeTextField= [[UITextField alloc] init];
        _codeTextField.font= [UIFont systemFontOfSize:14];
        _codeTextField.placeholder=@"请输入验证码";
        _codeTextField.layer.borderWidth=0;
        _codeTextField.textAlignment=NSTextAlignmentLeft;
        _codeTextField.delegate=self;
//        [_codeTextfield addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    }
    return _codeTextField;
}

- (UIView *)underLine{
    if (!_underLine) {
        _underLine = [[UIView alloc] init];
        _underLine.backgroundColor = UIColorFromRGB(0xf5f5f5);
    }
    return _underLine;
}

- (UIView *)underLine2{
    if (!_underLine2) {
        _underLine2 = [[UIView alloc] init];
        _underLine2.backgroundColor = UIColorFromRGB(0xf5f5f5);
    }
    return _underLine2;
}

- (JGCountDownButton *)countdownBtn{
    if (!_countdownBtn) {
        _countdownBtn = [JGCountDownButton countDownButtonWithTitle:@"获取验证码"
                                                     countDownTitle:@"秒后重新获取"
                                                         titleColor:UIColorFromRGB(0x37C8D7)
                                                countDownTitleColor:UIColorFromRGB(0x0099FF)];
        _countdownBtn.time = 60;
        _countdownBtn.titleLabel.font=[UIFont systemFontOfSize:17];
        _countdownBtn.titleLabel.textAlignment=NSTextAlignmentCenter;
      //  _countdownBtn.backgroundColor=UIColorFromRGB(0xf5f5f5);
 //       _countdownBtn.size = CGSizeMake(kAdaptedWidth(110), kAdaptedWidth(60));
        [_countdownBtn addTarget:self action:@selector(clickAuthBtnAction:)
                forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _countdownBtn;
}

- (UIButton *)nextBtn{
    if (!_nextBtn) {
        _nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_nextBtn addTarget:self action:@selector(clickNextAction) forControlEvents:UIControlEventTouchUpInside];
        [_nextBtn setTitle:@"下一步" forState:UIControlStateNormal];
        _nextBtn.titleLabel.font=[UIFont systemFontOfSize:16];
        _nextBtn.layer.cornerRadius = 4;
        _nextBtn.clipsToBounds = YES;
        _nextBtn.backgroundColor = UIColorFromRGB(0x37C8D7);
    }
    return _nextBtn;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
